﻿using NSubstitute;
using Sai.Core;
using Sai.Core.Reporting;
using Sai.Test.XUnit;
using Xunit;

namespace Sai.Test
{
    public class BinaryTypeChangeFacts
    {
        public class OnSerialization
        {
            
            [Fact, InMemoryTest]
            public void Basic_Construction_Reason_And_Message_Only_Are_Serialized()
            {
                BinaryTypeChange change = new BinaryTypeChange(TypeChangeReason.TypeTaxonomy, "This is a message");

                string output = ObjectFlattener<BinaryTypeChange>.Flatten(change);

                Assert.Contains("<BinaryTypeChange ", output);
                Assert.Contains("<Reason>TypeTaxonomy</Reason>", output);
                Assert.Contains("<Message>This is a message</Message>", output);
                Assert.Contains("</BinaryTypeChange>", output);
            }

            
            [Fact, InMemoryTest]
            public void SourceCode_Construction_Was_And_IsNow_Are_Serialized()
            {
                SourceCode wasCode = new SourceCode();
                wasCode.Add(new TypeNameTag("ThisIsMyOldType"));

                SourceCode isCode = new SourceCode();
                isCode.Add(new TypeNameTag("ThisIsMyNewType"));

                ISourceCodeProvider wasProvider = Substitute.For<ISourceCodeProvider>();
                wasProvider.ToCode().Returns(wasCode);

                ISourceCodeProvider isProvider = Substitute.For<ISourceCodeProvider>();
                isProvider.ToCode().Returns(isCode);

                BinaryTypeChange change = new BinaryTypeChange(TypeChangeReason.TypeTaxonomy, wasProvider, isProvider, "This is a message");

                string output = ObjectFlattener<BinaryTypeChange>.Flatten(change);

                Assert.Contains("<BinaryTypeChange ", output);
                Assert.Contains("<Reason>TypeTaxonomy</Reason>", output);
                Assert.Contains("<Was>", output);
                Assert.Contains("ThisIsMyOldType", output);
                Assert.Contains("</Was>", output);
                Assert.Contains("<IsNow>", output);
                Assert.Contains("ThisIsMyNewType", output);
                Assert.Contains("</IsNow>", output);
                Assert.Contains("<Message>This is a message</Message>", output);
                Assert.Contains("</BinaryTypeChange>", output);
            }

        }
    }
}
